package com.mm.ai.controller;

import com.mm.ai.common.dto.ResponseEntity;
import com.mm.ai.service.DockerContainerService;
import com.mm.ai.utils.DockerUtil;
import com.mm.ai.utils.UUIDUitl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @Author： tzy
 * @Date： 2024/11/18 22:00
 */
@Controller
@RequestMapping("/docker")
public class DockerController {

    private static final String createQRcodeUrl1 = "https://api.pwmqr.com/qrcode/create/?url=https://login.weixin.qq.com/l/";
    private static final String createQRcodeUrl2 = "https://my.tv.sohu.com/user/a/wvideo/getQRCode.do?text=https://login.weixin.qq.com/l/";
    private static final String createQRcodeUrl3 = "https://api.qrserver.com/v1/create-qr-code/?size=400×400&data=https://login.weixin.qq.com/l/";
    private static final String createQRcodeUrl4 = "https://api.isoyu.com/qr/?m=1&e=L&p=20&url=https://login.weixin.qq.com/l/";


    @Autowired
    private DockerContainerService dockerContainerService;

    @GetMapping("/")
    public String showEditor(Model model) {
        return "coze";
    }

    @GetMapping("/api/qr-code")
    @ResponseBody
    public ResponseEntity<String> getQRCodeAsImage(@RequestParam(value = "containerId") String containerId, HttpServletResponse response) throws IOException {
        dockerContainerService.startContainer(containerId);
        // 生成唯一ID作为二维码内容
        return ResponseEntity.ok(createQRcodeUrl1 + UUIDUitl.generateUUID());
    }
}
